// 方法聚合

import { getToken } from "@/utils/auth"

export default {
    // 字典查询
    fnQueryDic (targetKey, dic = [], keyName = 'key', valueName = 'value') {
        let target = targetKey

        for (let item of dic) {
            if (item[keyName] == targetKey) {
                target = item[valueName]
                break
            }
        }

        return target
    },

    // 用新标签打开其他系统的页面
    fnOpenSystem (url, systemName = 'zhuanJia') {
        let ip = ''

        // 要是有多个系统的话建议还是配置下ip
        if (systemName === 'zhuanJia') {
            ip = 'http://192.168.1.222:8128'
        }

        let
            params = '',
            championsoft = window.encodeURIComponent(getToken())

        if (url.includes('?')) {
            params = `&championsoft=${championsoft}`
        } else {
            params = `?championsoft=${championsoft}`
        }

        if (!url.startsWith('/')) {
            ip += '/'
        }

        window.open(ip + url + params, '_blank')
    }
}